#pragma once

#include "StopLight.h"
#include "Intersection.h"
#include "DrivingLane.h"

#include <cstdlib>
#include <fstream>
/asdfaad

namespace TrafficSim {
//gdag
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace System::IO;

	/// <summary>
	/// Summary for TrafficSim
	/// </summary>
	public ref class TrafficSim : public System::Windows::Forms::Form
	{
	public:
		TrafficSim(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~TrafficSim()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Panel^  panel1;
	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::Label^  label3;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::TextBox^  leftTurnTextBox;
	private: System::Windows::Forms::TextBox^  parkingExitTextBox;
	private: System::Windows::Forms::TextBox^  southboundTextBox;
	private: System::Windows::Forms::TextBox^  northboundTextBox;
	private: System::Windows::Forms::Label^  label5;
	private: System::Windows::Forms::TextBox^  fileNameTextBox;
	private: System::Windows::Forms::Label^  label6;
	private: System::Windows::Forms::Button^  submitButton;
	private: System::Windows::Forms::Panel^  panel2;
	private: System::Windows::Forms::TextBox^  epsilonTextBox;

	private: System::Windows::Forms::TextBox^  deltaTextBox;

	private: System::Windows::Forms::TextBox^  betaTextBox;


	private: System::Windows::Forms::TextBox^  alphaTextBox;

	private: System::Windows::Forms::Label^  label10;
	private: System::Windows::Forms::Label^  label9;
	private: System::Windows::Forms::Label^  label8;
	private: System::Windows::Forms::Label^  label7;
	private: System::Windows::Forms::Label^  label11;

	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->panel1 = (gcnew System::Windows::Forms::Panel());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->leftTurnTextBox = (gcnew System::Windows::Forms::TextBox());
			this->parkingExitTextBox = (gcnew System::Windows::Forms::TextBox());
			this->southboundTextBox = (gcnew System::Windows::Forms::TextBox());
			this->northboundTextBox = (gcnew System::Windows::Forms::TextBox());
			this->label5 = (gcnew System::Windows::Forms::Label());
			this->fileNameTextBox = (gcnew System::Windows::Forms::TextBox());
			this->label6 = (gcnew System::Windows::Forms::Label());
			this->submitButton = (gcnew System::Windows::Forms::Button());
			this->panel2 = (gcnew System::Windows::Forms::Panel());
			this->epsilonTextBox = (gcnew System::Windows::Forms::TextBox());
			this->deltaTextBox = (gcnew System::Windows::Forms::TextBox());
			this->betaTextBox = (gcnew System::Windows::Forms::TextBox());
			this->alphaTextBox = (gcnew System::Windows::Forms::TextBox());
			this->label10 = (gcnew System::Windows::Forms::Label());
			this->label9 = (gcnew System::Windows::Forms::Label());
			this->label8 = (gcnew System::Windows::Forms::Label());
			this->label7 = (gcnew System::Windows::Forms::Label());
			this->label11 = (gcnew System::Windows::Forms::Label());
			this->panel1->SuspendLayout();
			this->panel2->SuspendLayout();
			this->SuspendLayout();
			// 
			// panel1
			// 
			this->panel1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
			this->panel1->Controls->Add(this->label4);
			this->panel1->Controls->Add(this->label3);
			this->panel1->Controls->Add(this->label2);
			this->panel1->Controls->Add(this->label1);
			this->panel1->Controls->Add(this->leftTurnTextBox);
			this->panel1->Controls->Add(this->parkingExitTextBox);
			this->panel1->Controls->Add(this->southboundTextBox);
			this->panel1->Controls->Add(this->northboundTextBox);
			this->panel1->Location = System::Drawing::Point(12, 25);
			this->panel1->Name = L"panel1";
			this->panel1->Size = System::Drawing::Size(260, 128);
			this->panel1->TabIndex = 0;
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->Location = System::Drawing::Point(150, 73);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(63, 13);
			this->label4->TabIndex = 7;
			this->label4->Text = L"Parking Exit";
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(150, 7);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(50, 13);
			this->label3->TabIndex = 6;
			this->label3->Text = L"Left Turn";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(3, 73);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(65, 13);
			this->label2->TabIndex = 5;
			this->label2->Text = L"Southbound";
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(4, 4);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(63, 13);
			this->label1->TabIndex = 4;
			this->label1->Text = L"Northbound";
			// 
			// leftTurnTextBox
			// 
			this->leftTurnTextBox->Location = System::Drawing::Point(153, 23);
			this->leftTurnTextBox->Name = L"leftTurnTextBox";
			this->leftTurnTextBox->Size = System::Drawing::Size(100, 20);
			this->leftTurnTextBox->TabIndex = 3;
			this->leftTurnTextBox->Text = L"10";
			// 
			// parkingExitTextBox
			// 
			this->parkingExitTextBox->Location = System::Drawing::Point(153, 89);
			this->parkingExitTextBox->Name = L"parkingExitTextBox";
			this->parkingExitTextBox->Size = System::Drawing::Size(100, 20);
			this->parkingExitTextBox->TabIndex = 2;
			this->parkingExitTextBox->Text = L"20";
			// 
			// southboundTextBox
			// 
			this->southboundTextBox->Location = System::Drawing::Point(3, 89);
			this->southboundTextBox->Name = L"southboundTextBox";
			this->southboundTextBox->Size = System::Drawing::Size(100, 20);
			this->southboundTextBox->TabIndex = 1;
			this->southboundTextBox->Text = L"40";
			// 
			// northboundTextBox
			// 
			this->northboundTextBox->Location = System::Drawing::Point(3, 23);
			this->northboundTextBox->Name = L"northboundTextBox";
			this->northboundTextBox->Size = System::Drawing::Size(100, 20);
			this->northboundTextBox->TabIndex = 0;
			this->northboundTextBox->Text = L"30";
			// 
			// label5
			// 
			this->label5->AutoSize = true;
			this->label5->Location = System::Drawing::Point(12, 9);
			this->label5->Name = L"label5";
			this->label5->Size = System::Drawing::Size(44, 13);
			this->label5->TabIndex = 8;
			this->label5->Text = L"Percent";
			// 
			// fileNameTextBox
			// 
			this->fileNameTextBox->Location = System::Drawing::Point(12, 336);
			this->fileNameTextBox->Name = L"fileNameTextBox";
			this->fileNameTextBox->Size = System::Drawing::Size(166, 20);
			this->fileNameTextBox->TabIndex = 9;
			this->fileNameTextBox->Text = L"Enter File Name";
			this->fileNameTextBox->TextChanged += gcnew System::EventHandler(this, &TrafficSim::fileNameTextBox_TextChanged);
			// 
			// label6
			// 
			this->label6->AutoSize = true;
			this->label6->Location = System::Drawing::Point(9, 320);
			this->label6->Name = L"label6";
			this->label6->Size = System::Drawing::Size(54, 13);
			this->label6->TabIndex = 10;
			this->label6->Text = L"File Name";
			// 
			// submitButton
			// 
			this->submitButton->Location = System::Drawing::Point(197, 333);
			this->submitButton->Name = L"submitButton";
			this->submitButton->Size = System::Drawing::Size(75, 23);
			this->submitButton->TabIndex = 11;
			this->submitButton->Text = L"Submit";
			this->submitButton->UseVisualStyleBackColor = true;
			this->submitButton->Click += gcnew System::EventHandler(this, &TrafficSim::SubmitButton_Click);
			// 
			// panel2
			// 
			this->panel2->BackgroundImageLayout = System::Windows::Forms::ImageLayout::None;
			this->panel2->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
			this->panel2->Controls->Add(this->epsilonTextBox);
			this->panel2->Controls->Add(this->deltaTextBox);
			this->panel2->Controls->Add(this->betaTextBox);
			this->panel2->Controls->Add(this->alphaTextBox);
			this->panel2->Controls->Add(this->label10);
			this->panel2->Controls->Add(this->label9);
			this->panel2->Controls->Add(this->label8);
			this->panel2->Controls->Add(this->label7);
			this->panel2->Location = System::Drawing::Point(12, 175);
			this->panel2->Name = L"panel2";
			this->panel2->Size = System::Drawing::Size(260, 129);
			this->panel2->TabIndex = 12;
			// 
			// epsilonTextBox
			// 
			this->epsilonTextBox->Location = System::Drawing::Point(155, 83);
			this->epsilonTextBox->Name = L"epsilonTextBox";
			this->epsilonTextBox->Size = System::Drawing::Size(100, 20);
			this->epsilonTextBox->TabIndex = 7;
			this->epsilonTextBox->Text = L"7";
			// 
			// deltaTextBox
			// 
			this->deltaTextBox->Location = System::Drawing::Point(8, 83);
			this->deltaTextBox->Name = L"deltaTextBox";
			this->deltaTextBox->Size = System::Drawing::Size(100, 20);
			this->deltaTextBox->TabIndex = 6;
			this->deltaTextBox->Text = L"6";
			this->deltaTextBox->TextChanged += gcnew System::EventHandler(this, &TrafficSim::deltaTextBox_TextChanged);
			// 
			// betaTextBox
			// 
			this->betaTextBox->Location = System::Drawing::Point(155, 29);
			this->betaTextBox->Name = L"betaTextBox";
			this->betaTextBox->Size = System::Drawing::Size(100, 20);
			this->betaTextBox->TabIndex = 5;
			this->betaTextBox->Text = L"3";
			// 
			// alphaTextBox
			// 
			this->alphaTextBox->Location = System::Drawing::Point(8, 29);
			this->alphaTextBox->Name = L"alphaTextBox";
			this->alphaTextBox->Size = System::Drawing::Size(100, 20);
			this->alphaTextBox->TabIndex = 4;
			this->alphaTextBox->Text = L"5";
			// 
			// label10
			// 
			this->label10->AutoSize = true;
			this->label10->Location = System::Drawing::Point(6, 63);
			this->label10->Name = L"label10";
			this->label10->Size = System::Drawing::Size(32, 13);
			this->label10->TabIndex = 3;
			this->label10->Text = L"Delta";
			// 
			// label9
			// 
			this->label9->AutoSize = true;
			this->label9->Location = System::Drawing::Point(152, 63);
			this->label9->Name = L"label9";
			this->label9->Size = System::Drawing::Size(41, 13);
			this->label9->TabIndex = 2;
			this->label9->Text = L"Epsilon";
			// 
			// label8
			// 
			this->label8->AutoSize = true;
			this->label8->Location = System::Drawing::Point(153, 13);
			this->label8->Name = L"label8";
			this->label8->Size = System::Drawing::Size(29, 13);
			this->label8->TabIndex = 1;
			this->label8->Text = L"Beta";
			// 
			// label7
			// 
			this->label7->AutoSize = true;
			this->label7->Location = System::Drawing::Point(6, 13);
			this->label7->Name = L"label7";
			this->label7->Size = System::Drawing::Size(34, 13);
			this->label7->TabIndex = 0;
			this->label7->Text = L"Alpha";
			// 
			// label11
			// 
			this->label11->AutoSize = true;
			this->label11->Location = System::Drawing::Point(12, 160);
			this->label11->Name = L"label11";
			this->label11->Size = System::Drawing::Size(87, 13);
			this->label11->TabIndex = 13;
			this->label11->Text = L"Lane Parameters";
			// 
			// TrafficSim
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(288, 368);
			this->Controls->Add(this->label11);
			this->Controls->Add(this->panel2);
			this->Controls->Add(this->submitButton);
			this->Controls->Add(this->label6);
			this->Controls->Add(this->fileNameTextBox);
			this->Controls->Add(this->label5);
			this->Controls->Add(this->panel1);
			this->Name = L"TrafficSim";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = L"TrafficSim";
			this->Load += gcnew System::EventHandler(this, &TrafficSim::TrafficSim_Load);
			this->panel1->ResumeLayout(false);
			this->panel1->PerformLayout();
			this->panel2->ResumeLayout(false);
			this->panel2->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void TrafficSim_Load(System::Object^  sender, System::EventArgs^  e) {
			 }
private: System::Void SubmitButton_Click(System::Object^  sender, System::EventArgs^  e) {
			 int north, south, leftTurn, parkingExit, alpha, beta, delta, epsilon;
			 north = System::Convert::ToInt32(northboundTextBox->Text);
			 south = System::Convert::ToInt32(southboundTextBox->Text);
			 leftTurn = System::Convert::ToInt32(leftTurnTextBox->Text);
			 parkingExit = System::Convert::ToInt32(parkingExitTextBox->Text);

			 alpha = System::Convert::ToInt32(alphaTextBox->Text);
			 beta = System::Convert::ToInt32(betaTextBox->Text);
			 delta = System::Convert::ToInt32(deltaTextBox->Text);
			 epsilon = System::Convert::ToInt32(epsilonTextBox->Text);

			 int northT = 0;
			 int southT = 0;
			 int turnT = 0;
			 int exitT = 0;


			 if(north < 0 || north > 100){
				northboundTextBox->Text = "Invalid Entry";
			 }else if(south < 0 || south > 100){
				southboundTextBox->Text = "Invalid Entry";
			 }else if(leftTurn < 0 || leftTurn > 100){
				leftTurnTextBox->Text = "Invalid Entry";
			 }else if(parkingExit < 0 || parkingExit > 100){
				parkingExitTextBox->Text = "Invalid Entry";
			 }else{
			 
				if((north + south + leftTurn + parkingExit) != 100){
					System::Windows::Forms::MessageBox::Show("Sum is not equal to 100");
				}else{

				
				//-------------------StopLight Testing-------------------
				//StopLight light;
				//betaTextBox->Text = light.printMode();
				//alphaTextBox->Text = light.outputStats();
	
				//light.changeMode(light.getMode() + 1);
				//betaTextBox->Text = light.printMode();
				//alphaTextBox->Text = light.outputStats();

				//light.changeMode(light.getMode() + 1);
				//betaTextBox->Text = light.printMode();
				//alphaTextBox->Text = light.outputStats();

				//-------------------DrivingLane Testing-------------------
				//drivingLane lane;
				//int northbound = north;
				//int counter=0;
				//int totaldrivers = 1000;

				//int northbounddriver = totaldrivers * northbound;

				//for (int i = 0; i < northbounddriver; i++)
				//{
				//	lane.addDriver();
				//}

				//while (lane.getNumberOfDriversInLane()> 0) {
				//	int random = rand() % 11;
				//	alphaTextBox->Text = random.ToString();
				//	int drivernumber = lane.getNumberOfDriversInLane()- random;
				//	for (int i = 0; i < random; i++)
				//	{
				//		lane.exitLane();
				//	}
				//	northbounddriver = drivernumber;
				//	counter++;
				//	betaTextBox->Text = lane.getNumberOfDriversInLane().ToString();
				//}

				//-------------------Intersection Testing-------------------
				//Intersection Inter;
				//
				//Inter.southAddDriver();
				//Inter.southRemoveDriver();

				//// tests to see if both the getter and isEmpty are working correctly
				//if(Inter.isEmpty(Inter.getNumberOfDrivers()) == 0){
				//	alphaTextBox->Text = "It is empty.";
				//}else{
				//	betaTextBox->Text = "It is not empty. ";
				//	deltaTextBox->Text = Inter.getNumberOfDrivers().ToString();
				//}

				StreamWriter^ sw = gcnew StreamWriter(fileNameTextBox->Text + ".txt");
				//Text file is in the TrafficSim folder

				//sw->WriteLine("This is a test!");
				Intersection Inter;

				//starts with north south lights being green
				//Inter.northChangeMode(2);
				//Inter.southChangeMode(2);

				int countOfCars = 0;
				//counter for epsilon 
				int numberOfCarsArrivedAtLight = 0;
				int random;

				//run 1000 cars through intersection
				while(countOfCars <= 1000){	

					//to output current lane car count and current light
					if(Inter.getNorthMode() == 2 && Inter.getSouthMode() == 2){
						sw->WriteLine("N: " + Inter.getNorthNumberOfDrivers() + " S: " + Inter.getSouthNumberOfDrivers() + " L: " + Inter.getTurnNumberOfDrivers() + " X: " + Inter.getExitNumberOfDrivers() + " (Current Light: North/South)");
					}else if(Inter.getNorthMode() == 2 && Inter.getTurnMode() == 2){
						sw->WriteLine("N: " + Inter.getNorthNumberOfDrivers() + " S: " + Inter.getSouthNumberOfDrivers() + " L: " + Inter.getTurnNumberOfDrivers() + " X: " + Inter.getExitNumberOfDrivers() + " (Current Light: North/Left)");
					}else{
						sw->WriteLine("N: " + Inter.getNorthNumberOfDrivers() + " S: " + Inter.getSouthNumberOfDrivers() + " L: " + Inter.getTurnNumberOfDrivers() + " X: " + Inter.getExitNumberOfDrivers() + " (Current Light: Parking Lot Exit)");
					}
										
					//populates the lanes with their percent
					random = rand() %101;
					if(random <= north){
						Inter.northAddDriver();
						northT++;
						numberOfCarsArrivedAtLight++;


					}else if(random > north && random <= (north + south)){
						Inter.southAddDriver();
						southT++;
						numberOfCarsArrivedAtLight++;


					}else if(random > (north + south) && random <= (north + south + leftTurn)){
						Inter.turnAddDriver();
						turnT++;
						numberOfCarsArrivedAtLight++;


					}else{
						Inter.exitAddDriver();
						exitT++;
						numberOfCarsArrivedAtLight++;


					}

					//increment the number of cars added to intersection
					countOfCars++;

					//mode 1 --- less than alpha + 1 in left turn lane && beta are more than north and southbound combine
					if(Inter.getTurnNumberOfDrivers() < alpha + 1 && (Inter.getNorthNumberOfDrivers() + Inter.getSouthNumberOfDrivers()) > beta){
						
						sw->WriteLine();
						sw->WriteLine("NORTH/SOUTH LIGHT TURNS GREEN:");
						sw->WriteLine(Inter.getNorthNumberOfDrivers() + " vehicles northbound,");
						sw->WriteLine(Inter.getSouthNumberOfDrivers() + " vehicles southbound.");
						sw->WriteLine();

						Inter.northChangeMode(2);
						Inter.southChangeMode(2);
						Inter.turnChangeMode(0);
						Inter.exitChangeMode(0);

						for(int i = 0; i < Inter.getNorthNumberOfDrivers(); i++){
							Inter.northRemoveDriver();
						}
						for(int i = 0; i < Inter.getSouthNumberOfDrivers(); i++){
							Inter.southRemoveDriver();
						}


						numberOfCarsArrivedAtLight = 0;

					//mode 2 --- more that alpha in left turn lane
					}else if(Inter.getTurnNumberOfDrivers() > alpha){

						sw->WriteLine();
						sw->WriteLine("LEFT TURN LIGHT TURNS GREEN:");
						sw->WriteLine(Inter.getTurnNumberOfDrivers() + " vehicles turning left,");
						sw->WriteLine(Inter.getNorthNumberOfDrivers() + " vehicles northbound.");
						sw->WriteLine();

						Inter.northChangeMode(2);
						Inter.southChangeMode(0);
						Inter.turnChangeMode(2);
						Inter.exitChangeMode(0);

						for(int i = 0; i < Inter.getNorthNumberOfDrivers(); i++){
							Inter.northRemoveDriver();
						}
						for(int i = 0; i < Inter.getTurnNumberOfDrivers(); i++){
							Inter.turnRemoveDriver();
						}

						numberOfCarsArrivedAtLight = 0;
					
					//mode 3 --- less than alpha + 1 in left turn lane && less than beta + 1 are waiting in north and southbound combine && at least delta drives are waiting to exit exit
					}else if(Inter.getTurnNumberOfDrivers() < alpha + 1 &&  (Inter.getNorthNumberOfDrivers() + Inter.getSouthNumberOfDrivers()) < beta + 1 && Inter.getExitNumberOfDrivers() >= delta){

						sw->WriteLine();
						sw->WriteLine("PARKING LOT EXIT LIGHT TURNS GREEN:");
						sw->WriteLine(Inter.getExitNumberOfDrivers() + " vehicles exiting.");
						sw->WriteLine();


						Inter.northChangeMode(0);
						Inter.southChangeMode(0);
						Inter.turnChangeMode(0);
						Inter.exitChangeMode(2);

						for(int i = 0; i < Inter.getExitNumberOfDrivers(); i++){
							Inter.exitRemoveDriver();
						}

						numberOfCarsArrivedAtLight = 0;
					
					//no specific case is meet
					}else{

						//if lights are in mode 1 after epsilon cars arrive
						if(Inter.getNorthMode() == 2 && Inter.getSouthMode() == 2 && Inter.getTurnMode() == 0 && Inter.getTurnMode() == 0 && numberOfCarsArrivedAtLight >= epsilon){

							sw->WriteLine();
							sw->WriteLine("LEFT TURN LIGHT TURNS GREEN:");
							sw->WriteLine(Inter.getTurnNumberOfDrivers() + " vehicles turning left,");
							sw->WriteLine(Inter.getNorthNumberOfDrivers() + " vehicles northbound.");
							sw->WriteLine();

							//change lights to mode 2 
							Inter.northChangeMode(2);
							Inter.southChangeMode(0);
							Inter.turnChangeMode(2);
							Inter.exitChangeMode(0);

							for(int i = 0; i < Inter.getNorthNumberOfDrivers(); i++){
								Inter.northRemoveDriver();
							}
							for(int i = 0; i < Inter.getTurnNumberOfDrivers(); i++){
								Inter.turnRemoveDriver();
							}

							numberOfCarsArrivedAtLight = 0;
						
						//if lights are in mode 2 after epsilon cars arrive
						}else if(Inter.getNorthMode() == 2 && Inter.getSouthMode() == 0 && Inter.getTurnMode() == 2 && Inter.getTurnMode() == 0 && numberOfCarsArrivedAtLight >= epsilon){

							sw->WriteLine();
							sw->WriteLine("PARKING LOT EXIT LIGHT TURNS GREEN:");
							sw->WriteLine(Inter.getExitNumberOfDrivers() + " vehicles exiting.");	
							sw->WriteLine();

							//change lights to mode 3
							Inter.northChangeMode(0);
							Inter.southChangeMode(0);
							Inter.turnChangeMode(0);
							Inter.exitChangeMode(2);

							for(int i = 0; i < Inter.getExitNumberOfDrivers(); i++){
								Inter.exitRemoveDriver();
							}

							numberOfCarsArrivedAtLight = 0;

						//if lights are in mode 3 after epsilon cars arrive
						}else if(Inter.getNorthMode() == 0 && Inter.getSouthMode() == 0 && Inter.getTurnMode() == 2 && Inter.getTurnMode() == 2 && numberOfCarsArrivedAtLight >= epsilon){

							sw->WriteLine();
							sw->WriteLine("NORTH/SOUTH LIGHT TURNS GREEN:");
							sw->WriteLine(Inter.getNorthNumberOfDrivers() + " vehicles northbound,");
							sw->WriteLine(Inter.getSouthNumberOfDrivers() + " vehicles southbound.");
							sw->WriteLine();

							//change lights to mode 1
							Inter.northChangeMode(2);
							Inter.southChangeMode(2);
							Inter.turnChangeMode(0);
							Inter.exitChangeMode(0);

							for(int i = 0; i < Inter.getNorthNumberOfDrivers(); i++){
								Inter.northRemoveDriver();
							}
							for(int i = 0; i < Inter.getSouthNumberOfDrivers(); i++){
								Inter.southRemoveDriver();
							}

							numberOfCarsArrivedAtLight = 0;

						}						

					}

					//if light if green then keep removing cars that enter that light
					if(Inter.getNorthMode() == 2 && Inter.getSouthMode() == 2){
						if(Inter.getNorthNumberOfDrivers() > 0){
							Inter.northRemoveDriver();
						}
						if(Inter.getSouthNumberOfDrivers() > 0){
							Inter.southRemoveDriver();
						}
					}else if(Inter.getNorthMode() == 2 && Inter.getTurnMode() == 2){
						if(Inter.getNorthNumberOfDrivers() > 0){
							Inter.northRemoveDriver();
						}
						if(Inter.getTurnNumberOfDrivers() > 0){
							Inter.turnRemoveDriver();
						}
					}else{
						if(Inter.getExitNumberOfDrivers() > 0){
							Inter.exitRemoveDriver();
						}						
					}						
				}

				sw->WriteLine();
				sw->WriteLine("Totals:");
				sw->WriteLine("North: " + northT);
				sw->WriteLine("South: " + southT);
				sw->WriteLine("Left Turn: " + turnT);
				sw->WriteLine("Parking Exit: " + exitT);

				sw->WriteLine();
				sw->WriteLine("Wait Times:");
				sw->WriteLine("Worst Wait Time Possible: " + epsilon * 3);
				sw->WriteLine("North Average: " + (100 -  north - north) / 20);
				sw->WriteLine("South Average: " + (south / 10));
				sw->WriteLine("Left Turn Average: " + leftTurn);
				sw->WriteLine("Parking Exit Average: " + parkingExit);

				sw->Close();
				}
			 }
		 }

			
private: System::Void fileNameTextBox_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void panel2_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
		 }


private: System::Void deltaTextBox_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
};
}
